package com.example.common.Util;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class BreathDataUtil {
    private int year,month,day;
    private String[] months_big = { "1", "3", "5", "7", "8", "10", "12" };
    private String[] months_little = { "4", "6", "9", "11" };
    private List<String> list_big = Arrays.asList(months_big);
    private List<String> list_little = Arrays.asList(months_little);

    public BreathDataUtil(){
        Calendar calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH)+1;
        day = calendar.get(Calendar.DATE);
//        hour = calendar.get(Calendar.HOUR);
//        minute = calendar.get(Calendar.MINUTE);
    }
    public String GetDate(){
        String data=year+"-";
        //2019-
        if(month<10)
        {
            //2019-0
            data=data+"0";
        }
        //2019-01
        data=data+month+"-";
        if(day<10){
            //2019-01-0
            data=data+"0";
        }
        //2019-01-01
        data=data+day;
        return data;
    }

    public void ReduceADay(){
        if(day==1){
            month--;
            if(month==0){
                //处理跨年情况
                year--;
                month=12;
                day=31;
            }
            else if (list_big.contains(String.valueOf(month))){
                //大月
                day=31;
            }
            else if (list_little.contains(String.valueOf(month-1))){
                //小月
                day=30;
            }
            else{
                day=28;
            }
        }else{
            day--;
        }
    }
}
